package com.etong.frame.directive.factory;

import java.util.Map;

import com.etong.frame.directive.DefaultDirective;
import com.etong.frame.directive.Directive;
import com.etong.frame.directive.DirectiveConfig;
import com.etong.frame.directive.GroupConfig;
import com.etong.frame.directive.checker.CheckerGroup;
import com.etong.frame.directive.util.CommonStatus;

/**
 * @ClassName : DirectiveWrapper
 * @Description : 指令包装类，用于将组配置信息覆盖指令配置信息
 * @author : yuanjie
 * @date : 2016年4月11日 上午11:11:43
 * 
 */
public class DirectiveWrapper extends DefaultDirective {
	private DefaultDirective directive;
	//
	private GroupConfig groupConfig;

	public DirectiveWrapper(Directive directive, GroupConfig groupConfig) {
		super(directive.getDirectiveConfig());
		this.directive = (DefaultDirective) (directive);
		this.setGroupConfig(groupConfig);
	}

	@Override
	public CheckerGroup getCheckerGroup() {
		return groupConfig.getCheckerGroup();
	}

	@Override
	public void setCheckerGroup(CheckerGroup checkerGroup) {
		groupConfig.setCheckerGroup(checkerGroup);
	}

	@Override
	public boolean isBatch() {
		return directive.isBatch();
	}

	@Override
	public Directive buildBatch(Map<String, Object> vars) {
		return directive.buildBatch(vars);
	}

	@Override
	public CommonStatus execute(Map<String, Object> vars) {
		return directive.execute(vars, groupConfig);
	}

	public CommonStatus buildDirective(Map<String, Object> vars) {
		return directive.buildDirective(vars);
	}

	@Override
	public String getName() {
		return directive.getName();
	}

	@Override
	public DirectiveConfig getDirectiveConfig() {
		return directive.getDirectiveConfig();
	}

	public GroupConfig getGroupConfig() {
		return groupConfig;
	}

	public void setGroupConfig(GroupConfig groupConfig) {
		this.groupConfig = groupConfig;
	}

	@Override
	public String getOuputName() {
		if (null == groupConfig.getOutput_name()
				|| groupConfig.getOutput_name().isEmpty()) {
			return directive.getOuputName();
		} else {
			return groupConfig.getOutput_name();
		}
	}

	@Override
	public Boolean isOutput() {
		return null == groupConfig.getIs_output() ? false : groupConfig
				.getIs_output();
	}

	@Override
	public Boolean isOutputNext() {
		return null == groupConfig.getOutput_next() ? false : groupConfig
				.getOutput_next();
	}

	@Override
	public Integer getOutputFormat() {
		if (null != groupConfig.getOutput_format()) {
			return groupConfig.getOutput_format();
		} else {
			return directive.getOutputFormat();
		}
	}
}
